package com.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.pojo.FlightExcel;
import com.pojo.FlightExcelGet;
import com.pojo.RouteSchedule;
import com.pojo.TempRoute;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName RouteListener
 * @Author lenovo
 * @Date 2023/12/1 17:15
 * @Version 1.0
 * @Description TODO
 **/
public class TempRouteLisener extends AnalysisEventListener<TempRoute> {
    private final List<TempRoute> tempRoutes = new LinkedList<>();
    List<Double[]> list = new ArrayList<>();
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public static List<RouteSchedule> routeSchedules = new ArrayList<>();

    public static List<RouteSchedule> getRouteSchedules() {
        return routeSchedules;
    }

    public void invoke(TempRoute tempRoute, AnalysisContext analysisContext) {
        list.add(new Double[]{tempRoute.getLongitude(), tempRoute.getLatitude()});
    }

    /**
     * 所有数据读取完了调用
     */
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        RouteSchedule routeSchedule = new RouteSchedule();
        routeSchedule.setRouteName(name);

        routeSchedule.setPath(JSON.toJSONString(list));
        list = new ArrayList<>();
        routeSchedules.add(routeSchedule);
    }
}
